<?php 
header('Content-type:text/html;charset=utf-8');

function checkImg($img){
	if($img == 100)	{
		return 100;
	}else{
		$arr = array('jpg','gif','png','jpeg');
		$form = ltrim(strrchr($img,'.'),'.');
		$re = in_array($form, $arr);
		return $re;	
	}
	
}
$file = isset($_POST['file']) ? $_POST['file'] : 100;
//print_r($_FILES);
//$filess = 'D:\12.jpg';
//$newfiles = './2.jpg';
//copy($filess, $newfiles);
 ?>



<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<title>Document</title>
	<style>
		*{
			margin: 0;
			padding: 0;
			list-style: none;
			font-family: "微软雅黑";
		}
		#box{
			width: 800px;
			height: 650px;
			box-shadow: 0 1px 3px 2px rgba(0,0,0,.2);
			margin: 20px auto;
		}
		#box .top{
			height: 46px;
			line-height: 46px;
			background: -webkit-linear-gradient(#fff,#f7f7f7);
			/*box-shadow: 0 1px 3px 2px rgba(0,0,0,.2);*/
			border-bottom: 1px solid #ccc;
		}
		#box .top h1{
			font-style: normal;
			font-weight: 400;
			color: #666;
			margin-left: 20px;
			font-size: 25px;
		}
		#box .foot h2{
			margin-top: 10px;
			border-bottom: 1px solid #ccc;
			line-height: 40px;
			font-weight: 400;
			font-size: 20px;
			text-align: center;

		}
		#box .foot .body{
			margin-top: 10px;
			/*text-align: center;*/
		}
		#box .foot .body .span{
			margin-left: 30px;
		}
		#box .foot .body .box2{
			text-align: center;
			border: ;
		}
		#box .foot .body .box2 form{
			margin-top: 300px;
		}
		#box .foot .body .box2 form #sub{
			margin-top: 50px;
			width: 100px;
			height: 50px;
			margin-left: -165px;
		}
		#box .foot .body .box2 .yl{
			display: none;
		}
	</style>
</head>
<body>
	<div id="box">
		<div class="top">
			<h1>头像设置</h1>
		</div>
		<div class="foot">
			<h2> 自定义头像</h2>
			<div class="body">
				<div class="span">
					<span>选择本地照片，上传自己的头像</span>
				</div>
				<div class="box2">
					<form action="" method="post">
						<input type="file" name="file" id="shangchuan" value="" /><br />
						<input type="submit" id="sub" value="保存头像"/>
					</form>
					<div class="yl">
						<img src=""/>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script>
		var ofile = document.getElementById("shangchuan");
		var sss = ofile.value;
		console.log(ofile);
		<?php if(checkImg($file)==1){ ?>
			alert('头像上传成功!');
		<?php }elseif(checkImg($file)==100){ ?>
			alert('请上传图片');
		<?php }else{ ?>
			alert('您上传的不是图片!');
		<?php } ?>
	</script>
</body>
</html>